﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Drawing2D;

namespace 桌面视频录制
{
    [Serializable]
    public class DrawImage : DrawRectangle
    {
        private byte[] imageBytes;

        public byte[] ImageBytes
        {
            get { return imageBytes; }
            set { imageBytes = value; }
        }
        public DrawImage(byte[] imageBytes, Point leftUpPoint)
        {
            this.imageBytes = imageBytes;
            this.leftUpPoint = leftUpPoint;
            this.rightUpPoint = new Point(leftUpPoint.X, leftUpPoint.Y);
            this.leftDownPoint = new Point(leftUpPoint.X, leftUpPoint.Y);
            this.rightDownPoint = new Point(leftUpPoint.X, leftUpPoint.Y);
        }
        public override void Draw(Graphics g)
        {
            if (width != 0 && height != 0)
            {
                using (MemoryStream ms=new MemoryStream(imageBytes))
                {
                    using (Image image = Image.FromStream(ms))
                    {
                        Matrix matrix = new Matrix();
                        matrix.RotateAt((float)(angle * 180 / Math.PI), leftUpPoint);
                        g.Transform = matrix;
                        g.DrawImage(image, leftUpPoint.X, leftUpPoint.Y, width, height);
                        g.ResetTransform();
                        matrix.Dispose();
                    }
                }
            }
        }
        public override string ToString()
        {
            string printMsg = "[图片(" + this.leftUpPoint.X + "," + this.leftUpPoint.Y + ")]->[ID:" + this.Id + "]";
            return printMsg;
        }
        public override string GetDrawObjectMsg()
        {
            string drawObjectMsg = "图片->起始位置(" + this.leftUpPoint.X + "," + this.leftUpPoint.Y + "),宽高(" + this.width + "," + this.height + "),偏移角度:" + ((int)(angle * 180 / Math.PI)) + "°";
            return drawObjectMsg;
        }
    }
}
